<template>
    <!-- <Input v-model="value" placeholder="Enter something..."  /> -->
    <!--<Input v-model="url" search enter-button="search" placeholder="Enter something..." style="width: 500px;margin-top:180px;margin-left:350px "/>-->
  <!-- <div class="container">
    <div class="block">
      <span class="demonstration">请选择自然周</span>
      <el-date-picker
        v-model="value1"
        type="week"
        format="yyyy 第 WW 周"
        placeholder="选择周">
      </el-date-picker>
      <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
    </div>
  <div><img src="../assets/003.jpg" width="600" height="400" alt="" /></div>
  <div><span style="font-size: 18px">词云样例</span></div></div> -->

<div class="hello">
  <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/start' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>时间设置</el-breadcrumb-item></el-breadcrumb>
    <h1>微博舆情监控参数设置</h1>
    <UL>
      <!-- <li>起始时间: <input v-model="config.time1" placeholder="例如2019-10-10"></li> -->
       <el-date-picker
        v-model="config.time1"
        type="date"
        value-format="yyyy/MM/dd"
        placeholder="选择开始日期">
      </el-date-picker>
        <el-date-picker
        v-model="config.time2"
        type="date"
        value-format="yyyy/MM/dd"
        placeholder="选择结束日期">
      </el-date-picker>
      <!-- <li>结束时间: <input v-model="config.time2" placeholder="例如2019-10-10"></li> -->
      
    </UL>
    <h3>{{message}}</h3>
    <el-button @click="setConfig" :loading="loading" >保存参数设置</el-button>
<div><img src="../assets/day_cloud1.png" width="400" height="250" alt="" /></div>
<div><span style="font-size: 18px">2020年1月1日词云样例</span></div>

  </div>


</template>

<script>
import axios from 'axios'
export default {
  name: 'Config',
  data () {
    return {
      config: {time1:'',time2:''},
      message: '',
      loading:false
    }
  },
  methods: {
    getConfig () {
      const path = `http://127.0.0.1:5000/config`
      axios.get(path)
        .then(response => {
          // alert(response.data.config)
          this.config = response.data.config
        })
        .catch(error => {
          console.log(error)
        })
    },
    setConfig () {
      this.loading = true
      const path = `http://127.0.0.1:5000/config`
      var timestart =  this.config.time1
      var timeend = this.config.time2
      if(timestart.split('/')[1].indexOf('0') != -1 ){
        console.log(timestart.split('/')[1].substring(1,2))
        console.log(timestart.split('/')[1])
        timestart = timestart.split('/')[0]  + '/' + timestart.split('/')[1].substring(1,2) + '/' + timestart.split('/')[2]
        console.log(timestart)
      }
      if(timestart.split('/')[2].indexOf('0') != -1 ){
          timestart = timestart.split('/')[0]  + '/' + timestart.split('/')[1] + '/' + timestart.split('/')[2].substring(1,2)
      }
       if(timeend.split('/')[1].indexOf('0') != -1 ){
        timeend = timeend.split('/')[0]  + '/' + timeend.split('/')[1].substring(1,2) + '/' + timeend.split('/')[2]
      }
      if(timeend.split('/')[2].indexOf('0') != -1 ){
          timeend = timeend.split('/')[0]  + '/' + timeend.split('/')[1] + '/' + timeend.split('/')[2].substring(1,2)
      }
      var param = {"time1" : timestart,"time2": timeend}
      console.log(param)
      axios.post(path, param)
        .then(response => {
          this.loading = false
          // alert(response.data.config)
          // this.message = response.data.message
          this.$message({
          message:  response.data.message,
          type: 'success'
        });
      
        })
        .catch(error => {
          this.loading = true
          console.log(error)
        })
    }
  },
  created () {
    this.getConfig()
  }
}
</script>

<style>

</style>
